s=2;p=0;k=2;i=10;o=s*(i-1)+k-2*p;c=3;b=4;d=2;
X=rand(i,i,c,b);
F=rand(k,k,d,c);
Y1=vl_nnconvt(X,F,[],'Upsample',s);
size(Y1,1)==o;


k_=k;s_=1;p_=k-p-1;dilate_sz=s-1;dilate_X=[];F1=[];
for it=1:c
    for jt=1:b
        mask=zeros(dilate_sz+1);mask(1,1)=1;
        temp=kron(X(:,:,it,jt),mask);
        temp(:,end-dilate_sz+1:end)=[];
        temp(end-dilate_sz+1:end,:)=[];
        dilate_X(:,:,it,jt)=temp;
    end
    for jt=1:d
        F1(:,:,it,jt)=flipud(fliplr(F(:,:,jt,it)));
    end
end

Y2=vl_nnconv(dilate_X,F1,[],'Pad',[p_,p_,p_,p_],'Stride',s_);

norm(Y1(:)-Y2(:))